package com.team10.hotel.service.impl;

import com.team10.hotel.domain.Breakfast;
import com.team10.hotel.domain.BreakfastImage;
import com.team10.hotel.mapper.BreakfastImageMapper;
import com.team10.hotel.mapper.BreakfastMapper;
import com.team10.hotel.service.BreakfastService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class BreakfastServiceImpl implements BreakfastService {
    @Autowired
    private BreakfastMapper breakfastMapper;
    @Autowired
    private BreakfastImageMapper breakfastImageMapper;
    @Override
    public List<Breakfast> listBreakfast(Integer id) {
        return breakfastMapper.selectBreakfastByHotelId(id);
    }

    @Override
    public int insertBrk(Breakfast breakfast) {
        return breakfastMapper.insert(breakfast);
    }

    @Override
    public Breakfast findBrkOfHotel(Integer id) {
        return breakfastMapper.selectByPrimaryKey(id);
    }

    @Override
    public int deleteBrkByPrimaryKey(Integer id) {
        List<BreakfastImage>breakfastImages=breakfastImageMapper.selectBreakfastImageByBreakfastId(id);
        for (BreakfastImage breakfastImage:breakfastImages
             ) {
            breakfastImageMapper.deleteByPrimaryKey(breakfastImage.getImageId());
        }
        return breakfastMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateBrk(Breakfast breakfast) {
        return breakfastMapper.updateByPrimaryKey(breakfast);
    }

    @Override
    public List<Breakfast> listBreakfastAndImage(Integer id) {
        return breakfastMapper.selectBreakfastAndImage(id);
    }
}
